package com.ethannhu.todaynews.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding
import com.ethannhu.todaynews.entity.response.BaseResponse
import com.ethannhu.todaynews.model.BaseViewModel
import com.ethannhu.todaynews.util.ReflectUtil

abstract class BaseViewModelFragment<T : ViewBinding> : BaseLogicFragment() {
    private var _binding: T? = null
    protected val binding get() = _binding!!

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        _binding = ReflectUtil.newViewBinding(layoutInflater, javaClass)
    }

    override fun getLayoutView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return binding.root
    }

    override fun onDestroyView() {
        super.onDestroyView()
        //防止内存泄露
        _binding = null
    }
}